from typing import List
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, Text, ForeignKey, DateTime, UniqueConstraint, Index
from sqlalchemy.orm import sessionmaker
from pydantic import BaseModel

from pathlib import Path
import sys
PROJECT_PATH = Path(__file__).parent.parent.absolute()
sys.path.append(str(PROJECT_PATH))

engine = create_engine('mysql+pymysql://dms:dms@test.zyys.tech:31601/doc?charset=utf8',pool_size=20,pool_recycle=280) 

class DocSummaryMain(declarative_base()):
    __tablename__ = 'doc_summary_main'
    id = Column(String(20),primary_key=True)
    doc_name = Column(String(255))
    doc_summary = Column(String(2000))

def save_doc_summary(id,doc_name, doc_summary):
    Session = sessionmaker(bind=engine)
    session = Session()
    doc_summary_main = DocSummaryMain(id=id, doc_name=doc_name, doc_summary=doc_summary)
    session.add(doc_summary_main)
    session.commit()

def query_all_doc_summary_wrapper():
    output_list = []
    for summary in query_all_doc_summary():
        output_list.append([summary.id,summary.doc_name,summary.doc_summary])
    return output_list

def query_all_doc_summary():
    Session = sessionmaker(bind=engine)
    session = Session()
    doc_summary = session.query(DocSummaryMain).all()
    return doc_summary

if __name__ == '__main__':
    save_doc_summary('111','222','333')
    print(query_all_doc_summary())